package com.example.aircraft.aircraft;


import android.media.MediaPlayer;
import android.util.Log;

import com.example.aircraft.MyApplication;
import com.example.aircraft.R;
import com.example.aircraft.base.MusicThread;
import com.example.aircraft.bullet.AbstractBullet;
import com.example.aircraft.prop.AbstractProp;
import com.example.aircraft.prop.PropFactory;

import java.util.LinkedList;
import java.util.List;


public abstract class Enemy extends AbstractAircraft{
    protected MediaPlayer hitedEffect;
    protected int power = 0;
    public Enemy(int locationX, int locationY, int speedX, int speedY, int hp) {
        super(locationX, locationY, speedX, speedY, hp);
        this.hitedEffect = MediaPlayer.create(MyApplication.getContext(),R.raw.bullet_hit);
        this.hitedEffect.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
            @Override
            public void onCompletion(MediaPlayer mediaPlayer) {
                hitedEffect.reset();
            }
        });
    }
    @Override
    public void forward() {
        super.forward();
        // 判定 y 轴向下飞行出界
        if (locationY >= MyApplication.getContext().getResources().getDisplayMetrics().heightPixels ) {
            vanish();
        }
    }
    @Override
    public List<AbstractBullet> shoot() {
        return launchBarrage.Launch(locationX,locationY,hp/2,"Enemy");
    }

    public List<AbstractProp> dropProp(){
//        Log.d("TAG", "准备掉落！");
        List<AbstractProp> res = new LinkedList<>();
        double seed = Math.random();

        if(seed<=0.5)
        {
            res.add(PropFactory.setProp("Blood",this.getLocationX(),
                    this.getLocationY()));
        }
        else if(seed>0.5&&seed<=0.8)
        {
            res.add(PropFactory.setProp("Bullet",this.getLocationX(),
                    this.getLocationY()));
        }
        else if (seed>0.8)
        {
            res.add(PropFactory.setProp("Bomb",this.getLocationX(),
                    this.getLocationY()));
        }
        return res;
    }

    @Override
    public void decreaseHp(int decrease) {
        super.decreaseHp(decrease);

    if(MyApplication.isMusicOn()){
        this.hitedEffect.start();
        this.hitedEffect.setLooping(false);}



    }



    public int getValue(){
        return 0;
    }
    @Override
    public void update(){
        this.decreaseHp(this.hp);
    }
}
